#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

ll n;
void solve()
{
	cin >> n;
	if (n <= 6)
	{
		if (n == 1)
		{
			cout << 1 << '\n';
			return;
		}
		if (n == 2)
		{
			cout << -1 << '\n';
			return;
		}
		if (n == 3)
		{
			cout << 2 << '\n';
			return;
		}
		if (n == 4)
		{
			cout << 2 << '\n';
			return;
		}
		if (n == 5)
		{
			cout << 3 << '\n';
			return;
		}
		if (n == 6)
		{
			cout << 4 << '\n';
			return;
		}

	}

	n -= 6;
	if ((n - 5) % 6 == 0)
	{
		ll t = (n - 5) / 6;
		cout << (ll)(7 + 4 * t) << '\n';
		return;
	}
	if ((n - 6) % 6 == 0)
	{
		ll t = (n - 6) / 6;
		cout << (ll)(8 + 4 * t) << '\n';
		return;
	}

	n--;
	ll cnt = n % 6;
	if (cnt == 1) cnt = 0;
	if (cnt == 2) cnt--;
	else if (cnt > 2) cnt -= 2;
	ll sum = n / 6;
	cout << (ll)((ll)sum * 4 + (ll)cnt + 5) << '\n';

}

int main()
{
	close();
	int T; cin >> T;
	while (T--) solve();
	return 0;
}